package com.Day1008;

import java.util.Arrays;

public class Text8 {
    public static void main(String[] args) {
        //  lambda 表达式
        int[] nums = {19,29,11,12,9};
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
        Student[] students = new Student[4];
        Student student1 = new Student("张三",Gender.FeMale,18);
        Student student2 = new Student("王梅",Gender.Male,20);
        Student student3 = new Student("11",Gender.FeMale,19);
        Student student4 = new Student("22",Gender.Male,22);
        students[0] = student4;
        students[1] = student3;
        students[2] = student2;
        students[3] = student1;
        MyComparator myComparator = new MyComparator();
        //Arrays.sort(students,myComparator);
//        lambda表达式 不需要实现接口
        //  compare  方法简写   lambda表达式   Java8新特性  用的少,用到了也不会难
//    只有一个参数的时候,小括号可省
//    如果方法体只有一行语句,大括号可省
//    可以省略访问修饰符,返回值类型和方法名
        Arrays.sort(students,(Student o1, Student o2) ->{
            if (o1.getAge() < o2.getAge()){
                return -1;
            }
            return 0;
        });

        //System.out.println(Arrays.toString(students));
        for (Student student : students) {
            System.out.println(student);
        }
    }
}
